package com.sgb.kjwl.viewmodel.enterprise;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.enterprise.AssesTypeEntiy;
import com.sgb.kjwl.model.entity.enterprise.CompanyPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.CopyrightPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.model.entity.enterprise.PatentPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.PropertyPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishCompanyDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishCopyrightDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishPatentDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishPropertyDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishTradeDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.TrademarkPublishEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PublishViewModel extends AndroidViewModel {

    public MutableLiveData<List<TrademarkPublishEntity>> trademarkListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<CopyrightPublishEntity>> copyrightListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<PatentPublishEntity>> patentListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<PropertyPublishEntity>> propertyListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<CompanyPublishEntity>> companyListLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> mChangeSuccess = new MutableLiveData<>();
    public MutableLiveData<PublishTradeDetailEntity> mPublishTradeDetailLiveData = new MutableLiveData<>();
    public MutableLiveData<PublishPatentDetailEntity> mPublishPatentDetailLiveData = new MutableLiveData<>();
    public MutableLiveData<PublishCopyrightDetailEntity> mPublishCopyrightDetailLiveData = new MutableLiveData<>();
    public MutableLiveData<PublishPropertyDetailEntity> mPublishPropertyDetailLiveData = new MutableLiveData<>();
    public MutableLiveData<PublishCompanyDetailEntity> mPublishCompanyDetailLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> mDeleteSuccess = new MutableLiveData<>();
    public MutableLiveData<Boolean> mSaveSuccessTrademark = new MutableLiveData<>();
    public MutableLiveData<Boolean> mSaveSuccessCopyright = new MutableLiveData<>();
    public MutableLiveData<Boolean> mSaveSuccessPatent = new MutableLiveData<>();
    public MutableLiveData<Boolean> mSaveSuccessCompany = new MutableLiveData<>();
    public MutableLiveData<Boolean> mSaveSuccessProperty = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mTrademarkTypeListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mPatentClassListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mPatentTypeListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mCopyrightTypeListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mEnterpriseTypeListLiveData = new MutableLiveData<>();//getEnterpriseModelOption
    public MutableLiveData<List<IpPickSelectEntity>> mEnterpriseModelOption = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mIndustryTypeListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<AssesTypeEntiy>> mPropertyTypeListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<IpPickSelectEntity>> mPropertyOldOrNewListLiveData = new MutableLiveData<>();
    public MutableLiveData<List<String>> uploadFileSuccess = new MutableLiveData<>();
    public MutableLiveData<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>> mAreaLiveData = new MutableLiveData<>();
    public MutableLiveData<Integer> mDeleteSecess_Type = new MutableLiveData<>();
    public MutableLiveData<Integer> mJump = new MutableLiveData<>();
    public MutableLiveData<List<String>> tableName = new MutableLiveData<>();
    public MutableLiveData<String> payStatus = new MutableLiveData<>();

    public PublishViewModel(@NonNull Application application) {
        super(application);
    }

    public void getMakeOverPublishTradeList(Context context, Map<String, Object> map) {
        map.put("payStatus", payStatus.getValue());
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getMakeOverPublishTradeList(map).enqueue(new Callback<BaseEntity<ListResponse<List<TrademarkPublishEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<TrademarkPublishEntity>>>> call, Response<BaseEntity<ListResponse<List<TrademarkPublishEntity>>>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    trademarkListLiveData.postValue(response.body().getData().getList());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<TrademarkPublishEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getMakeOverPublishCopyrightList(Context context, Map<String, Object> map) {
        map.put("payStatus", payStatus.getValue());
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getMakeOverPublishCopyrightList(map).enqueue(new Callback<BaseEntity<ListResponse<List<CopyrightPublishEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<CopyrightPublishEntity>>>> call, Response<BaseEntity<ListResponse<List<CopyrightPublishEntity>>>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    copyrightListLiveData.postValue(response.body().getData().getList());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }

            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<CopyrightPublishEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getMakeOverPublishPatentList(Context context, Map<String, Object> map) {
        map.put("payStatus", payStatus.getValue());
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getMakeOverPublishPatentList(map).enqueue(new Callback<BaseEntity<ListResponse<List<PatentPublishEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<PatentPublishEntity>>>> call, Response<BaseEntity<ListResponse<List<PatentPublishEntity>>>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    patentListLiveData.postValue(response.body().getData().getList());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }

            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<PatentPublishEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getMakeOverPublishPropertyList(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getMakeOverPublishPropertyList(map).enqueue(new Callback<BaseEntity<ListResponse<List<PropertyPublishEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<PropertyPublishEntity>>>> call, Response<BaseEntity<ListResponse<List<PropertyPublishEntity>>>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    propertyListLiveData.postValue(response.body().getData().getList());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<PropertyPublishEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getMakeOverPublishCompanyList(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getMakeOverPublishCompanyList(map).enqueue(new Callback<BaseEntity<ListResponse<List<CompanyPublishEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<CompanyPublishEntity>>>> call, Response<BaseEntity<ListResponse<List<CompanyPublishEntity>>>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    companyListLiveData.postValue(response.body().getData().getList());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<CompanyPublishEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getPublishDetail(Context context, String id, int type) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPublishDetail(id, type).enqueue(new Callback<BaseEntity<PublishTradeDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PublishTradeDetailEntity>> call, Response<BaseEntity<PublishTradeDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPublishTradeDetailLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<PublishTradeDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getPatentPublishDetail(Context context, String id, int type) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPatentPublishDetail(id, type).enqueue(new Callback<BaseEntity<PublishPatentDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PublishPatentDetailEntity>> call, Response<BaseEntity<PublishPatentDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPublishPatentDetailLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<PublishPatentDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCopyrightPublishDetail(Context context, String id, int type) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getCopyrightPublishDetail(id, type).enqueue(new Callback<BaseEntity<PublishCopyrightDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PublishCopyrightDetailEntity>> call, Response<BaseEntity<PublishCopyrightDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPublishCopyrightDetailLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<PublishCopyrightDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getPropertyPublishDetail(Context context, String id, int type) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPropertyPublishDetail(id, type).enqueue(new Callback<BaseEntity<PublishPropertyDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PublishPropertyDetailEntity>> call, Response<BaseEntity<PublishPropertyDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPublishPropertyDetailLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<PublishPropertyDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCompanyPublishDetail(Context context, String id, int type) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getCompanyPublishDetail(id, type).enqueue(new Callback<BaseEntity<PublishCompanyDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PublishCompanyDetailEntity>> call, Response<BaseEntity<PublishCompanyDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPublishCompanyDetailLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<PublishCompanyDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void saveAndUpdateCompany(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().saveAndUpdateCompany(map).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mSaveSuccessCompany.postValue(true);
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void saveAndUpdateCopyright(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().saveAndUpdateCopyright(map).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mSaveSuccessCopyright.postValue(true);
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void saveAndUpdateTrademark(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().saveAndUpdateTrademark(map).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mSaveSuccessTrademark.postValue(true);
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void saveProperty(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().saveProperty(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mSaveSuccessProperty.postValue(true);
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void saveAndUpdatePatent(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().saveAndUpdatePatent(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mSaveSuccessPatent.postValue(true);
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void updateProperty(Context context, Map<String, Object> map) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().updateProperty(map).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mSaveSuccessProperty.postValue(true);
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void changeStateMakeoverPublish(Context context, long id, int type, String status) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().changeStateMakeoverPublish(id + "", type, status).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mChangeSuccess.postValue(true);
                    try {
                        switch (type) {
                            case 1:
                                PublishTradeDetailEntity data_Trade = mPublishTradeDetailLiveData.getValue();
                                data_Trade.setStatus(Integer.parseInt(status));
                                mPublishTradeDetailLiveData.postValue(data_Trade);
                                break;
                            case 2:
                                PublishPatentDetailEntity data_Patent = mPublishPatentDetailLiveData.getValue();
                                data_Patent.setStatus(Integer.parseInt(status));
                                mPublishPatentDetailLiveData.postValue(data_Patent);
                                break;
                            case 3:
                                PublishCopyrightDetailEntity data_Copyright = mPublishCopyrightDetailLiveData.getValue();
                                data_Copyright.setStatus(Integer.parseInt(status));
                                mPublishCopyrightDetailLiveData.postValue(data_Copyright);
                                break;

                            case 4:
                                PublishCompanyDetailEntity data_Company = mPublishCompanyDetailLiveData.getValue();
                                data_Company.setStatus(Integer.parseInt(status));
                                mPublishCompanyDetailLiveData.postValue(data_Company);
                                break;
                            case 5:
                                PublishPropertyDetailEntity data_Property = mPublishPropertyDetailLiveData.getValue();
                                data_Property.setStatus(Integer.parseInt(status));
                                mPublishPropertyDetailLiveData.postValue(data_Property);
                                break;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                mChangeSuccess.postValue(false);
            }
        });
    }

    public void deleteMakeoverPublish(Context context, String id, int type) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().deleteMakeoverPublish(id, type).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mDeleteSuccess.postValue(true);
                    mDeleteSecess_Type.postValue(type);
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                mDeleteSuccess.postValue(false);
            }
        });
    }

    public void jumpToChange(Context context, int type, Serializable entity) {
        mJump.postValue(type);
    }

    public void getTrademarkType(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTrademarkTypeOption_1().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mTrademarkTypeListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());

                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getTerritoryTypeOption(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTerritoryTypeOption().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPatentClassListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getPatentTypeOption(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPatentTypeOption().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPatentTypeListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCopyrightTypeOption(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getCopyrightTypeOption().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mCopyrightTypeListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getEnterpriseTypeOption() {
        List<IpPickSelectEntity> mEnterpriseType = new ArrayList<>();
        mEnterpriseType.add(new IpPickSelectEntity("0", "有限责任公司", "", "", "", "", ""));
        mEnterpriseType.add(new IpPickSelectEntity("1", "个人独资公司", "", "", "", "", ""));
        mEnterpriseType.add(new IpPickSelectEntity("2", "港澳台公司", "", "", "", "", ""));
        mEnterpriseType.add(new IpPickSelectEntity("3", "集团公司", "", "", "", "", ""));
        mEnterpriseTypeListLiveData.postValue(mEnterpriseType);
    }

    public void getEnterpriseModelOption() {
        List<IpPickSelectEntity> mEnterpriseType = new ArrayList<>();
        mEnterpriseType.add(new IpPickSelectEntity("0", "小规模", "", "", "", "", ""));
        mEnterpriseType.add(new IpPickSelectEntity("1", "一般纳税人", "", "", "", "", ""));
        mEnterpriseType.add(new IpPickSelectEntity("2", "出口纳税人", "", "", "", "", ""));
        mEnterpriseType.add(new IpPickSelectEntity("3", "未核税", "", "", "", "", ""));
        mEnterpriseModelOption.postValue(mEnterpriseType);
    }

    public void getTradeTypeOption(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTradeTypeOption().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mIndustryTypeListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCityList(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getCityList().enqueue(new Callback<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> call, Response<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mAreaLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void queryPropertyType(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().queryPropertyType_2().enqueue(new Callback<BaseEntity<List<AssesTypeEntiy>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<AssesTypeEntiy>>> call, Response<BaseEntity<List<AssesTypeEntiy>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPropertyTypeListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<AssesTypeEntiy>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getPropertyNewOrOldOption(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPropertyNewOrOldOption().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mPropertyOldOrNewListLiveData.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void uploadPicture(Context context, List<File> file) {
        Map<String, RequestBody> photos = new HashMap<>();
        for (int i = 0; i < file.size(); i++) {
            RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file.get(i));
            photos.put("file" + i + "\"; filename=\"" + "image.jpg\"", requestBody);
        }

        DialogHelper.showProgressDialog(context, null, "文件上传中...", 0, false, null).setCanceledOnTouchOutside(true);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().uploadPicture(photos).enqueue(new Callback<BaseEntity<List<String>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<String>>> call, Response<BaseEntity<List<String>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    uploadFileSuccess.postValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<String>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void setTableData() {
        List<String> list = new ArrayList<>();
        list.add("全部");
        list.add("在售中");
        list.add("交易中");
        list.add("已售出");
        tableName.postValue(list);
    }

    public void setPayStatus(int position) {
        switch (position) {
            case 0:
                payStatus.setValue(null);
                break;
            default:
                payStatus.setValue(position + "");
        }
    }
}
